package com.cmf.myproject.controller.boss.teamleave;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cmf.myproject.dal.mybatis.enums.TeamLeaveLeaveTypeEnum;
import com.cmf.myproject.dal.mybatis.model.TeamLeave;
import com.cmf.myproject.service.teamLeave.TeamLeaveService;
import com.cmf.myproject.service.teamLeave.dto.TeamLeaveAddItemReqDto;
import com.cmf.myproject.service.teamLeave.dto.TeamLeaveQueryFilter;
import com.cmf.myproject.service.teamLeave.dto.TeamLeaveUpdateItemReqDto;
import com.cmf.myproject.service.user.UserService;
import com.system.core.controller.ControllerBase;
import com.system.core.results.ResultBase;
import com.system.core.view.layui.table.TableViewRspDto;

@Controller
@RequestMapping("boss/team_leave")
public class TeamLeaveController extends ControllerBase {
	@Autowired
	private TeamLeaveService teamLeaveService;
	@Autowired
	private UserService userService;
	
	@RequiresPermissions("teamLeave_topage")
	@RequestMapping(value = "to_page",method = RequestMethod.GET)
	public String toPage() {
		getModelMap().put("users", userService.userEnableList());
		getModelMap().put("teamLeaveLeaveTypeEnum", TeamLeaveLeaveTypeEnum.getAllEnum());
		return "/boss/teamLeave/teamLeave-list";
	}
	
	@RequestMapping(value = "query_list",method = RequestMethod.POST)
	@ResponseBody
	public TableViewRspDto<TeamLeave> teamLeaveQueryList(TeamLeaveQueryFilter filter) {
		TableViewRspDto<TeamLeave> rsp = teamLeaveService.teamLeaveList(filter);
		return rsp;
	}
	
	@RequestMapping(value = "get_item_by_key",method = RequestMethod.POST)
	@ResponseBody
	public TeamLeave teamLeaveGetByPrimaryKey(TeamLeave teamLeave){
		return teamLeaveService.teamLeaveGetByPrimaryKey(teamLeave);
	}
	
	@RequiresPermissions("teamLeave_add_opt")
	@RequestMapping(value = "add_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase teamLeaveAddItem(@Validated TeamLeaveAddItemReqDto teamLeaveAddItemReqDto) {
		return teamLeaveService.teamLeaveSave(teamLeaveAddItemReqDto);
	}
	
	@RequiresPermissions("teamLeave_edit_opt")
	@RequestMapping(value = "update_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase teamLeaveUpdateItem(@Validated TeamLeaveUpdateItemReqDto teamLeaveUpdateItemReqDto) {
		return teamLeaveService.teamLeaveUpdateByPrimaryKey(teamLeaveUpdateItemReqDto);
	}
	
	@RequiresPermissions("teamLeave_delete_opt")
	@RequestMapping(value = "delete_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase teamLeaveDeleteItem(@RequestBody List<Long> keys) {
		return teamLeaveService.teamLeaveDeleteByPrimaryKey(keys);
	}
}
